<template>
    <el-container style="height: 100%; border: 1px solid #eee">
        <el-header style="text-align: right; font-size: 12px">
        <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>查看</el-dropdown-item>
            <el-dropdown-item>新增</el-dropdown-item>
            <el-dropdown-item>删除</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        <span>王小虎</span>
        </el-header>
         <el-container>
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu :default-openeds="['1']" :default-active="currentActiveIndex" :unique-opened='true' :router='true'>
        <el-submenu index="1">
            <template slot="title"><i class="el-icon-message"></i>人物家族</template>
            <!-- <el-menu-item-group> -->
            <!-- <template slot="title">分组一</template> -->
            <el-menu-item index="/index/figure">人物</el-menu-item>
            <el-menu-item index="/index/sect">家族</el-menu-item>
            <!-- </el-menu-item-group> -->
            <!-- <el-menu-item-group title="分组2"> -->
            <el-menu-item index="/index/beast">魔兽</el-menu-item>
            <!-- </el-menu-item-group> -->
            <el-submenu index="1-4">
            <template slot="title">选项4</template>
            <el-menu-item index="1-4-1">选项4-1</el-menu-item>
            </el-submenu>
        </el-submenu>
        <el-submenu index="2">
            <template slot="title"><i class="el-icon-menu"></i>功法斗技</template>
            <el-menu-item index="2-1">等级划分</el-menu-item>
            <el-menu-item index="2-2">功法</el-menu-item>
            <el-menu-item index="2-3">斗技</el-menu-item>
            <el-submenu index="2-4">
            <template slot="title">选项4</template>
            <el-menu-item index="2-4-1">选项4-1</el-menu-item>
            </el-submenu>
        </el-submenu>
        <el-submenu index="3">
            <template slot="title"><i class="el-icon-setting"></i>待定</template>
            <el-menu-item index="3-1">选项1</el-menu-item>
            <el-menu-item index="3-2">选项2</el-menu-item>
            <el-menu-item index="3-3">选项3</el-menu-item>
            <el-submenu index="3-4">
            <template slot="title">选项4</template>
            <el-menu-item index="3-4-1">选项4-1</el-menu-item>
            </el-submenu>
        </el-submenu>
        </el-menu>
    </el-aside>
    <div class="page-content">
      <router-view ></router-view>
    </div>
    </el-container>
    </el-container>
</template>
<style>

/*
	找到html标签、body标签，和挂载的标签
	都给他们统一设置样式
  html,body,#app,.el-container
*/
  html,body,#app,.el-container{
        /*设置内部填充为0，几个布局元素之间没有间距*/
        padding: 0px;
         /*外部间距也是如此设置*/
        margin: 0px;
        /*统一设置高度为100%*/
        height: 100%;

  }
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }
  
  .el-aside {
    color: #333;
  }
  .page-content {
        padding: 20px;
        height:100%;
        overflow-x: hidden;
        overflow-y:auto;
    }
</style>

<script>
 export default{
  //vue中的计算属性
 computed: {

        currentActiveIndex() {
            //计算当前在哪个路由
            const path = this.$route.path;
            const prefixVal = path.substring(1,path.indexOf('/',2));
            const prefix = `/${prefixVal}`;
            if(~path.indexOf(prefix)) {
                const reg = new RegExp('^\/'+prefixVal+'\/\\w+','ig');
               return path.match(reg)[0];
            }
            return path
        },
    },
 }

</script>
